#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QToolBar>
#include<QPushButton>
#include<QProgressBar>
#include<QDockWidget>
#include<QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QMenuBar*menubar=this->menuBar();
    this->setMenuBar(menubar);
    QToolBar*toolbar=new QToolBar();
    this->addToolBar(toolbar);
    QStatusBar*statusbar=this->statusBar();
    this->setStatusBar(statusbar);
    statusbar->showMessage("这是一个状态消息",0);
    QPushButton*button1=new QPushButton("按钮1");
    statusbar->addPermanentWidget(button1);
    QProgressBar* progressbar=new QProgressBar();
    progressbar->setRange(0,100);
    progressbar->setValue(50);
    statusbar->addPermanentWidget(progressbar);

    QDockWidget*dockwidget=new QDockWidget();
    this->addDockWidget(Qt::LeftDockWidgetArea,dockwidget);
    dockwidget->setWindowTitle("这是一个浮动窗口");
    QWidget*w=new QWidget();
    QPushButton*button2=new QPushButton("按钮");
    dockwidget->setWidget(w);
    QVBoxLayout*layout=new QVBoxLayout;
    w->setLayout(layout);
    layout->addWidget(button2);



    QMenu* menu1=new QMenu("文件(&A)");
    QMenu* menu2=new QMenu("编辑(&B)");
    QMenu* menu3=new QMenu("视图(&C)");
    QMenu* menu4=new QMenu("子菜单(&F)");

    menubar->addMenu(menu1);
    menubar->addMenu(menu2);
    menubar->addMenu(menu3);

    QAction* action1=new QAction("新建(&A)");
    QAction* action2=new QAction("打开(&B)");
    QAction* action3=new QAction("保存(&C)");
    QAction* action4=new QAction("退出(&D)");
    QAction* action5=new QAction("删除(&E)");
    QAction*action6=new QAction("保存");
    QAction*action7=new QAction("打开");
    action6->setIcon(QIcon(":/save.png"));
    action7->setIcon(QIcon(":/open.png"));
    toolbar->addAction(action6);
    toolbar->addAction(action7);
    action3->setIcon(QIcon(":/save.png"));
    action2->setIcon(QIcon(":/open.png"));
    menu4->setIcon(QIcon(":/list.png"));

    menu1->addMenu(menu4);
    menu4->addAction(action1);
    menu4->addAction(action2);
    menu4->addAction(action3);
    menu4->addAction(action4);
    menu4->addAction(action5);

    connect(action1,&QAction::triggered,this,&MainWindow::handle);
    connect(action5,&QAction::triggered,this,&MainWindow::close);
    connect(action6,&QAction::triggered,this,&MainWindow::handle);
    connect(action7,&QAction::triggered,this,&MainWindow::close);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle()
{
    qDebug()<<"触发新建操作";
}

//void MainWindow::handle_2()
//{
//    qDebug()<<"触发删除操作";
//}

